//
//  FriendCell.m
//  iHeima
//
//  Created by he chao on 5/29/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "FriendCell.h"

@implementation FriendCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)initSelf{
    self.backgroundColor = [UIColor whiteColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
    avatar = [AvatarView initFrame:CGRectMake(10, 10, 50, 50) image:nil borderColor:[UIColor clearColor]];
    //avatar.backgroundColor = [UIColor yellowColor];
    [self addSubview:avatar];
    
    name = [BaseLabel initLabel:@"周杰伦" font:FONT(16) color:RGB(83,83,83) textAlignment:NSTextAlignmentLeft];
    name.frame = CGRectMake(avatar.right+10, 15, 200, 20);
    [self addSubview:name];
    
    description = [BaseLabel initLabel:@"hi,大家好，我是Jay" font:FONT(14) color:RGB(145,145,145) textAlignment:NSTextAlignmentLeft];
    description.frame = CGRectMake(name.left, name.bottom+5, 200, 20);
    [self addSubview:description];
    
    badge = [BaseLabel initLabel:@"20" font:FONT(12) color:[UIColor whiteColor] textAlignment:NSTextAlignmentCenter];
    badge.backgroundColor = [UIColor redColor];
    CGSize sz = [badge.text sizeWithFont:badge.font byHeight:16];
    badge.frame = CGRectMake(avatar.right-sz.width/2.0, avatar.top, sz.width+3, sz.height);
    badge.layer.cornerRadius = 8;
    [self addSubview:badge];
}

- (void)load{
    
  
    name.text = self.dictUser[@"username"];
    description.text = self.dictUser[@"intro"];
    [avatar setImageWithURL:[NSString stringWithFormat:@"%@avatar.php?uid=%@&size=middle",kPicUrl,self.dictUser[@"uid"]] placeholderImage:IMAGESTRING(@"default_avatar")];
    //avatar.url = [NSString stringWithFormat:@"%@avatar.php?uid=%@&size=middle",kPicUrl,self.dictUser[@"uid"]];//@"http://www.iheima.com/uc_server/images/noavatar_middle.gif";//
    if ([self.dictUser[@"count"] intValue]>0) {
        badge.text = self.dictUser[@"count"];
        badge.hidden = NO;
    }
    else {
        badge.hidden = YES;
    }
        
    
}

@end
